/**
 * Created by Administrator on 2017/4/10.
 */






var limit=20;

var option='';


$(function () {



    function xin() {
        $.ajax({
            url: ctx + '/rentorder/selectRentOrdersCount',
            type: 'GET',
            success: function (data) {
                var text = data.split(',');
                var li=$('.CustomTabs ul li');

                if(text[0]>0){
                    if(li.eq(0).find('.CustomBadge').length>0){
                        li.eq(0).find('.CustomBadge').remove();
                        li.eq(0).Badge({data:{text:text[0]>99?'99+':text[0],state:'No'}})
                    }else {
                        li.eq(0).Badge({data:{text:text[0]>99?'99+':text[0],state:'No'}})
                    }
                }

                if(text[1]>0){
                    if(li.eq(7).find('.CustomBadge').length>0){
                        li.eq(7).find('.CustomBadge').remove();
                        li.eq(7).Badge({data:{text:text[1]>99?'99+':text[1],state:'No'}})
                    }else {
                        li.eq(7).Badge({data:{text:text[1]>99?'99+':text[1],state:'No'}})
                    }
                }

                if(text[2]>0){
                    if(li.eq(8).find('.CustomBadge').length>0){
                        li.eq(8).find('.CustomBadge').remove();
                        li.eq(8).Badge({data:{text:text[2]>99?'99+':text[2],state:'No'}})
                    }else {
                        li.eq(8).Badge({data:{text:text[2]>99?'99+':text[2],state:'No'}})
                    }
                }
            }
        })
    }
    xin();
    setInterval(function () {
        xin()
    }, 60000);


    $(".Nav .SEO .SEOButton").on("click", function () {
        option = $(".Nav .SEO  input").val();
            AlreadyPinSingleAjax(1,option)
    });


    AlreadyPinSingleAjax(1);

    $(document).keyup(function (event) {
        switch (event.keyCode) {
            case 13:
                $(".Nav .SEO .SEOButton").click();
                break;
        }
    });
    function AlreadyPinSingleAjax(page,inquireVal) {
        var AlreadyPinSingle={
            plateNoOrPassengerPhone:inquireVal ||'',
            status:'-5',
            'pager.offset':(page-1)*limit,
        	"limit":limit,
        };
        $.ajax({
            url:ctx+'/rentorder/selectRentOrders',
            type:"GET",
            data:AlreadyPinSingle,
            success:function (data) {
                var Message = {
                    data:{
                        Thead:{
                            PullDownAction:"操作",
                            // status:'订单状态',
                            OddNumbers:"单号",
                            totalFree:'总金额',
                            payed: '租金',
                            TakeCarWay:"取车地址",
                            CarWay:"还车地址",
                            LeaseTime:"预约时间",
                            CarTime:"还车时间",
                            // RemainingTime:"剩余时间",
                            CustomerName:"客户名称",
                            CustomerPhone:"客户电话",
                            PlateNumbers:"车辆牌号",
                            VehicleModel:"车辆型号",
                            // CharterBase:"租金标准",
                            PaysTheRent:"租车押金",
                            ViolationOfTheDeposit:"违章押金",
                            // GrantAmountInAdvance:"预授额度",
                            SubordinateCompanies:"所属公司",
                            Remark:"备注"
                        },
                        Tbody:[]

                    }
                };
                for(var i=0 ;i<data.content.length;i++){
                    (function () {
                        var index=i;
                        var val={
                            id:data.content[index].id,
                            PullDownAction:{
                                Default:{
                            name:"备注",
                                action:function (e) {
                                var SinglePin = {
                                    data: {
                                        Title: '备注',
                                        Content:"",
                                        OkChange: function(e){
                                            var textarea=e.find('textarea').val();
                                            var Single ={
                                                id:data.content[index].id,
                                                memo:textarea
                                            };
                                            $.ajax({
                                                url:ctx+'/rentorder/memo',
                                                data:Single,
                                                type:'POST',
                                                success:function () {
                                                    AlreadyPinSingleAjax(1)
                                                }
                                            })
                                        }
                                    }
                                };
                                SinglePin.data.Content=$('<textarea placeholder="请输入备注" autofocus ></textarea>').val(data.content[index].memo);
                                $('body').ModalBox(SinglePin);
                            }
                        },
                                data:[
                                    {
                                        name:'查看',
                                        action:function () {
                                            window.location.href=ctx+'/rentorder/orderinfo?id='+data.content[index].id;
                                        }
                                    }
                                ]
                            },
                            OddNumbers: data.content[index].orderNo,
                            totalFree:data.content[i].totalFee,
                            payed: '',
                            RetrievingMeans: data.content[index].takeCarWay == 1 ? data.content[index].startAddress : "门店自取",
                            ReturnType: data.content[index].backCarWay == 1 ? data.content[index].endAddress : '门店自还',
                            CarTime: data.content[index].bookTime?$.fn.Timestamp.TimestampDate(data.content[index].bookTime):'无',
                            LeaseTime: data.content[index].rentTime?$.fn.Timestamp.TimestampDate(data.content[index].rentTime):'无',

                            // RemainingTime:$.fn.Timestamp.DayCalculate(data.content[index].rentTime-Date.parse(new Date())/1000) ,
                            CustomerName: data.content[index].passengerName,
                            CustomerPhone: data.content[index].passengerPhone,
                            PlateNumbers:data.content[index].plateNo,
                            VehicleModel: data.content[index].category,
                            // CharterBase: data.content[index].CharterBase,
                            PaysTheRent: data.content[index].prepayRent,
                            ViolationOfTheDeposit: data.content[index].peccancyForegift,
                            // GrantAmountInAdvance: data.content[index].companyName,
                            SubordinateCompanies: data.content[index].companyName,
                            Remark: data.content[index].memo
                        };
                        switch (data.content[i].isPay) {
                            case 0:
                                val.payed = $('<span class="badge">未交付</span>');
                                break;
                            case 1:
                                val.payed = data.content[i].payed;
                                break;
                            case 2:
                                val.payed =data.content[i].payed;
                                break;
                            case 3:
                                val.payed = data.content[i].payed;
                                break;
                            case 4:
                                val.payed = '已结算';
                                break;
                        }

                        console.log(val);
                        Message.data.Tbody.push(val);
                    })()

                }
                var PagingMdOption = {
                    data: {
                        rows: 20,
                        nowrows: page,
                        Pages: '',
                        total:data.totalElements,
                        change: function (index) {           
                            AlreadyPinSingleAjax(index);
                        }
                    }
                };
                PagingMdOption.data.Pages=Math.ceil((PagingMdOption.data.total/PagingMdOption.data.rows));
                $(".Content").find('.CustomOrder').remove();
                $(".Content").find('.PagingMdPagingMd').remove();
                $(".Content").Order(Message);
                $(".Content").PagingMd(PagingMdOption)
            }
        });

    }

   
});


